home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / SCF.H < prev    next >
C/C++ Source or Header  |  1993-05-13  |  5KB  |  138 lines

  1. /* Copyright (C) 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* scf.h */
  20. /* Common definitions for CCITTFax encoding and decoding filters */
  21. #include "shc.h"
  22.  
  23. /*
  24.  * The CCITT Group 3 (T.4) and Group 4 (T.6) fax specifications map
  25.  * run lengths to Huffman codes.  White and black have different mappings.
  26.  * If the run length is 64 or greater, two codes are needed,
  27.  * a 'make-up' code that encodes the multiple of 64, and a 'termination'
  28.  * code for the remainder; for runs of 63 or less, only the 'termination'
  29.  * code is needed.
  30.  */
  31.  
  32. /* ------ Encoding tables ------ */
  33.  
  34. typedef hce_code cfe_run;
  35. #define cfe_entry(c, len) hce_entry(c, len)
  36.  
  37. /* Codes common to 1-D and 2-D encoding. */
  38. /* The decoding algorithms know that EOL is 0....01. */
  39. #define run_eol_code_length 12
  40. #define run_eol_code_value 1
  41. extern const cfe_run cf_run_eol;
  42. extern const cfe_run cf_white_termination[64];
  43. extern const cfe_run cf_white_make_up[41];
  44. extern const cfe_run cf_black_termination[64];
  45. extern const cfe_run cf_black_make_up[41];
  46. extern const cfe_run cf_uncompressed[6];
  47. extern const cfe_run cf_uncompressed_exit[10];    /* indexed by 2 x length of */
  48.             /* white run + (1 if next run black, 0 if white) */
  49. /* 1-D encoding. */
  50. extern const cfe_run cf1_run_uncompressed;
  51. /* 2-D encoding. */
  52. extern const cfe_run cf2_run_pass;
  53. #define cf2_run_vertical_offset 3
  54. extern const cfe_run cf2_run_vertical[7];    /* indexed by b1 - a1 + offset */
  55. extern const cfe_run cf2_run_horizontal;
  56. extern const cfe_run cf2_run_uncompressed;
  57. /* 2-D Group 3 encoding. */
  58. extern const cfe_run cf2_run_eol_1d;
  59. extern const cfe_run cf2_run_eol_2d;
  60.  
  61. /* ------ Decoding tables ------ */
  62.  
  63. typedef hcd_code cfd_node;
  64. #define run_length value
  65.  
  66. /*
  67.  * The value in the decoding tables is either a white or black run length,
  68.  * or a (negative) exceptional value.
  69.  */
  70. #define run_error hcd_value_error
  71. #define run_zeros (-2)    /* EOL follows, possibly with more padding first */
  72. #define run_uncompressed (-3)
  73. /* 2-D codes */
  74. #define run2_pass (-4)
  75. #define run2_horizontal (-5)
  76.  
  77. #define cfd_white_initial_bits 8
  78. extern const cfd_node far_data cf_white_decode[];
  79. #define cfd_black_initial_bits 7
  80. extern const cfd_node far_data cf_black_decode[];
  81. #define cfd_2d_initial_bits 7
  82. extern const cfd_node far_data cf_2d_decode[];
  83. #define cfd_uncompressed_initial_bits 6        /* must be 6 */
  84. extern const cfd_node far_data cf_uncompressed_decode[];
  85.  
  86. /* ------ Run detection macros ------ */
  87.  
  88. /*
  89.  * For the run detection macros:
  90.  *   white_byte is 0 or 0xff for BlackIs1 or !BlackIs1 respectively;
  91.  *   data holds p[-1], inverted if !BlackIs1;
  92.  *   count is the number of valid bits remaining in the scan line.
  93.  */
  94.  
  95. /* Tables in scftab.c. */
  96. extern const byte cf_left_bits[8];
  97. extern const byte cf_top_bit[256];
  98.       
  99. /* Skip over white pixels to find the next black pixel in the input. */
  100. /* There are a lot more white pixels than black pixels, */
  101. /* so we go to some extra trouble to make this efficient. */
  102.  
  103. #define skip_white_pixels(data, p, count, white_byte, w0_unused)\
  104. { byte top = data & cf_left_bits[count & 7];\
  105.   if ( top ) count = ((count - 1) & ~7) + cf_top_bit[top];\
  106.   else\
  107.    { if ( white_byte == 0 )\
  108.       for ( ; ; p += 4, count -= 32 )\
  109.       { if ( p[0] ) { data = p[0]; p += 1; count -= 9; break; }\
  110.     if ( p[1] ) { data = p[1]; p += 2; count -= 17; break; }\
  111.     if ( p[2] ) { data = p[2]; p += 3; count -= 25; break; }\
  112.     if ( p[3] ) { data = p[3]; p += 4; count -= 33; break; }\
  113.       }\
  114.       else\
  115.       for ( ; ; p += 4, count -= 32 )\
  116.       { if ( p[0] != 0xff ) { data = ~p[0]; p += 1; count -= 9; break; }\
  117.     if ( p[1] != 0xff ) { data = ~p[1]; p += 2; count -= 17; break; }\
  118.     if ( p[2] != 0xff ) { data = ~p[2]; p += 3; count -= 25; break; }\
  119.     if ( p[3] != 0xff ) { data = ~p[3]; p += 4; count -= 33; break; }\
  120.       }\
  121.      count = (count & ~7) + cf_top_bit[data];\
  122.    }\
  123. }
  124.  
  125. /* Skip over black pixels to find the next white pixel in the input. */
  126.  
  127. #define skip_black_pixels(data, p, count, white_byte, b0_unused, b1_unused)\
  128. { byte top = ~data & cf_left_bits[count & 7];\
  129.   if ( top ) count = ((count - 1) & ~7) + cf_top_bit[top];\
  130.   else\
  131.    { if ( white_byte == 0 )\
  132.        while ( (data = *p++) == 0xff ) count -= 8;\
  133.      else\
  134.        while ( (data = ~*p++) == 0xff ) count -= 8;\
  135.      count = ((count - 9) & ~7) + cf_top_bit[data ^ 0xff];\
  136.    }\
  137. }
  138.